package views.accounting;

import javax.swing.JPanel;
import javax.swing.SpringLayout;
import javax.swing.JRadioButton;
import javax.swing.JSeparator;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import java.awt.Dimension;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JTextArea;
import java.awt.Font;
import java.awt.Color;
import java.awt.event.ActionListener;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.ButtonGroup;

public class Accounting extends JPanel 
{
	private JComboBox cbCategory;
	private JTextField tfAmount;
	private JComboBox comboBoxPaymentMethod;
	private JTextField tfChequeNo;
	private JTextField tfcustomerName;
	private JTextField tfChequeDate;
	private JButton btnChequeDate;
	private JTextField tfBranch;
	private JTextField tfBank;
	private JTextField tfCreditCard;
	private JTextField tfDate;
	private JButton btnDate;
	private JTextArea taDescription;
	private JButton btnAdd;
	private JButton btnSave;
	private JTable table;
	private final ButtonGroup buttonGroup = new ButtonGroup();
	private JRadioButton rdbtnExpense;
	private JRadioButton rdbtnIncome;
	private JRadioButton rdbtnPaySeller;
	private JRadioButton rdbtnAcceptPayment;
	
	public Accounting() 
	{
		SpringLayout springLayout = new SpringLayout();
		setLayout(springLayout);
		
		rdbtnExpense = new JRadioButton("Expense");
		buttonGroup.add(rdbtnExpense);
		rdbtnExpense.setActionCommand("Expense");
		rdbtnExpense.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, rdbtnExpense, 10, SpringLayout.NORTH, this);
		springLayout.putConstraint(SpringLayout.WEST, rdbtnExpense, 30, SpringLayout.WEST, this);
		add(rdbtnExpense);
		
		rdbtnIncome = new JRadioButton("Income");
		buttonGroup.add(rdbtnIncome);
		rdbtnIncome.setActionCommand("Income");
		rdbtnIncome.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, rdbtnIncome, 0, SpringLayout.NORTH, rdbtnExpense);
		springLayout.putConstraint(SpringLayout.WEST, rdbtnIncome, 10, SpringLayout.EAST, rdbtnExpense);
		add(rdbtnIncome);
		
		rdbtnPaySeller = new JRadioButton("Pay Seller");
		buttonGroup.add(rdbtnPaySeller);
		rdbtnPaySeller.setActionCommand("Pay Seller");
		rdbtnPaySeller.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, rdbtnPaySeller, 0, SpringLayout.NORTH, rdbtnExpense);
		springLayout.putConstraint(SpringLayout.WEST, rdbtnPaySeller, 10, SpringLayout.EAST, rdbtnIncome);
		add(rdbtnPaySeller);
		
		rdbtnAcceptPayment = new JRadioButton("Accept Payment");
		buttonGroup.add(rdbtnAcceptPayment);
		rdbtnAcceptPayment.setActionCommand("Accept Payment");
		rdbtnAcceptPayment.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, rdbtnAcceptPayment, 0, SpringLayout.NORTH, rdbtnExpense);
		springLayout.putConstraint(SpringLayout.WEST, rdbtnAcceptPayment, 10, SpringLayout.EAST, rdbtnPaySeller);
		add(rdbtnAcceptPayment);
		
		JSeparator separator = new JSeparator();
		springLayout.putConstraint(SpringLayout.NORTH, separator, 10, SpringLayout.SOUTH, rdbtnExpense);
		springLayout.putConstraint(SpringLayout.WEST, separator, 30, SpringLayout.WEST,this);
		springLayout.putConstraint(SpringLayout.EAST, separator, -30, SpringLayout.EAST,this);
		add(separator);
		
		JLabel lblCategory = new JLabel("Category");
		lblCategory.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, lblCategory, 10, SpringLayout.SOUTH, separator);
		springLayout.putConstraint(SpringLayout.WEST, lblCategory, 30, SpringLayout.WEST,this);
		add(lblCategory);
		
		cbCategory = new JComboBox();
		cbCategory.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, cbCategory, 6, SpringLayout.SOUTH, lblCategory);
		springLayout.putConstraint(SpringLayout.WEST, cbCategory, 30, SpringLayout.WEST, this);
		cbCategory.setPreferredSize(new Dimension(150, 20));
		add(cbCategory);
		
		JLabel lblAmount = new JLabel("Amount");
		lblAmount.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, lblAmount, 0, SpringLayout.NORTH, lblCategory);
		springLayout.putConstraint(SpringLayout.WEST, lblAmount, 20, SpringLayout.EAST,cbCategory);
		add(lblAmount);
		
		tfAmount = new JTextField();
		tfAmount.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, tfAmount, 0, SpringLayout.NORTH, cbCategory);
		springLayout.putConstraint(SpringLayout.WEST, tfAmount, 0, SpringLayout.WEST, lblAmount);
		add(tfAmount);
		tfAmount.setColumns(15);
		
		JLabel lblPaymentMethod = new JLabel("Payment Method");
		lblPaymentMethod.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, lblPaymentMethod, 0, SpringLayout.NORTH, lblCategory);
		springLayout.putConstraint(SpringLayout.WEST, lblPaymentMethod, 20, SpringLayout.EAST, tfAmount);
		add(lblPaymentMethod);
		
		comboBoxPaymentMethod = new JComboBox();
		comboBoxPaymentMethod.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, comboBoxPaymentMethod, 0, SpringLayout.NORTH, cbCategory);
		springLayout.putConstraint(SpringLayout.WEST, comboBoxPaymentMethod, 0, SpringLayout.WEST,lblPaymentMethod);
		comboBoxPaymentMethod.setPreferredSize(new Dimension(150, 20));
		comboBoxPaymentMethod.setMinimumSize(new Dimension(150, 20));
		add(comboBoxPaymentMethod);
		
		JLabel lblChequeNo = new JLabel("Cheque No");
		lblChequeNo.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, lblChequeNo, 10, SpringLayout.SOUTH, cbCategory);
		springLayout.putConstraint(SpringLayout.WEST, lblChequeNo, 30, SpringLayout.WEST,this);
		add(lblChequeNo);
		
		tfChequeNo = new JTextField();
		tfChequeNo.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, tfChequeNo,6, SpringLayout.SOUTH, lblChequeNo);
		springLayout.putConstraint(SpringLayout.WEST, tfChequeNo, 30, SpringLayout.WEST,this);
		add(tfChequeNo);
		tfChequeNo.setColumns(15);
		
		JLabel lblChequeDate = new JLabel("Cheque Date");
		lblChequeDate.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, lblChequeDate, 0, SpringLayout.NORTH, lblChequeNo);
		springLayout.putConstraint(SpringLayout.WEST, lblChequeDate, 10, SpringLayout.EAST, tfChequeNo);
		add(lblChequeDate);
		
		tfChequeDate = new JTextField();
		tfChequeDate.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.WEST, tfChequeDate, 6, SpringLayout.EAST, tfChequeNo);
		springLayout.putConstraint(SpringLayout.NORTH, tfChequeDate, 0, SpringLayout.NORTH, tfChequeNo);
		add(tfChequeDate);
		tfChequeDate.setColumns(15);
		
		btnChequeDate = new JButton("Cl");
		btnChequeDate.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, btnChequeDate, 0, SpringLayout.NORTH, tfChequeNo);
		springLayout.putConstraint(SpringLayout.WEST, btnChequeDate, 6, SpringLayout.EAST, tfChequeDate);
		add(btnChequeDate);
		btnChequeDate.setActionCommand("cheque date");
		
		JLabel lblBank = new JLabel("Bank");
		lblBank.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, lblBank, 0, SpringLayout.NORTH, lblChequeNo);
		springLayout.putConstraint(SpringLayout.WEST, lblBank, 10, SpringLayout.EAST, btnChequeDate);
		add(lblBank);
		
		tfBank = new JTextField();
		tfBank.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		tfBank.setPreferredSize(new Dimension(150, 20));
		springLayout.putConstraint(SpringLayout.NORTH, tfBank, 0, SpringLayout.NORTH, tfChequeNo);
		springLayout.putConstraint(SpringLayout.WEST, tfBank, 0, SpringLayout.WEST, lblBank);
		add(tfBank);
		
		JLabel lblBranch = new JLabel("Branch");
		lblBranch.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, lblBranch, 0, SpringLayout.NORTH, lblChequeNo);
		springLayout.putConstraint(SpringLayout.WEST, lblBranch, 10, SpringLayout.EAST, tfBank);
		add(lblBranch);
		
		tfBranch = new JTextField();
		tfBranch.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		tfBranch.setPreferredSize(new Dimension(150, 20));
		springLayout.putConstraint(SpringLayout.NORTH, tfBranch, 0, SpringLayout.NORTH, tfChequeNo);
		springLayout.putConstraint(SpringLayout.WEST, tfBranch, 0, SpringLayout.WEST, lblBranch);
		add(tfBranch);
		
		JLabel lblCreditCardNo = new JLabel("Credit Card No");
		lblCreditCardNo.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, lblCreditCardNo, 0, SpringLayout.NORTH, lblChequeNo);
		springLayout.putConstraint(SpringLayout.WEST, lblCreditCardNo, 10, SpringLayout.EAST,tfBranch);
		add(lblCreditCardNo);
		
		tfCreditCard = new JTextField();
		tfCreditCard.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, tfCreditCard, 0, SpringLayout.NORTH, tfChequeNo);
		springLayout.putConstraint(SpringLayout.WEST, tfCreditCard, 0, SpringLayout.WEST,lblCreditCardNo);
		add(tfCreditCard);
		tfCreditCard.setColumns(20);
		
		JLabel lblDate = new JLabel("Date");
		lblDate.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, lblDate, 0, SpringLayout.NORTH,lblPaymentMethod);
		springLayout.putConstraint(SpringLayout.WEST, lblDate, 10, SpringLayout.EAST,comboBoxPaymentMethod);
		add(lblDate);
		
		tfDate = new JTextField();
		tfDate.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, tfDate, 6, SpringLayout.SOUTH, lblDate);
		springLayout.putConstraint(SpringLayout.WEST, tfDate, 0, SpringLayout.WEST,lblDate);
		add(tfDate);
		tfDate.setColumns(15);
		
		btnDate = new JButton("Cl");
		btnDate.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, btnDate, 0, SpringLayout.NORTH, tfDate);
		springLayout.putConstraint(SpringLayout.WEST, btnDate, 6, SpringLayout.EAST, tfDate);
		add(btnDate);
		btnDate.setActionCommand("Date");
		
		JLabel lblDescription = new JLabel("Description");
		lblDescription.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, lblDescription, 10, SpringLayout.SOUTH,tfChequeNo);
		springLayout.putConstraint(SpringLayout.WEST, lblDescription,30, SpringLayout.WEST,this);
		add(lblDescription);
		
		taDescription = new JTextArea();
		taDescription.setBackground(Color.PINK);
		taDescription.setRows(2);
		taDescription.setColumns(100);
		springLayout.putConstraint(SpringLayout.NORTH, taDescription, 6, SpringLayout.SOUTH,lblDescription);
		springLayout.putConstraint(SpringLayout.WEST, taDescription, 0, SpringLayout.WEST, lblDescription);
		add(taDescription);
		
		btnAdd = new JButton("Add");
		btnAdd.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.NORTH, btnAdd, 0, SpringLayout.NORTH, taDescription);
		springLayout.putConstraint(SpringLayout.WEST, btnAdd, 20, SpringLayout.EAST, taDescription);
		add(btnAdd);
		btnAdd.setActionCommand("add");
		
		JSeparator separator_1 = new JSeparator();
		springLayout.putConstraint(SpringLayout.NORTH, separator_1, 10, SpringLayout.SOUTH, taDescription);
		springLayout.putConstraint(SpringLayout.WEST, separator_1, 30, SpringLayout.WEST,this);
		springLayout.putConstraint(SpringLayout.EAST, separator_1, -30, SpringLayout.EAST,this);
		add(separator_1);
		
		btnSave = new JButton("Save");
		btnSave.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.WEST, btnSave, 30, SpringLayout.WEST,this);
		springLayout.putConstraint(SpringLayout.SOUTH, btnSave, -10, SpringLayout.SOUTH, this);
		add(btnSave);
		btnSave.setActionCommand("save");
		
		JScrollPane scrollPane = new JScrollPane();
		springLayout.putConstraint(SpringLayout.NORTH, scrollPane, 10, SpringLayout.SOUTH, separator_1);
		springLayout.putConstraint(SpringLayout.WEST, scrollPane, 30, SpringLayout.WEST,this);
		springLayout.putConstraint(SpringLayout.EAST, scrollPane, -30, SpringLayout.EAST,this);
		springLayout.putConstraint(SpringLayout.SOUTH, scrollPane, -10, SpringLayout.NORTH,btnSave);
		add(scrollPane);
		
		table = new JTable();
		table.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"Sr.No.", "Tag", "Category", "Amount", "Payment Method", "Date", "Delete"
			}
		));
		scrollPane.setViewportView(table);
	}
	/***********************************************************************/
	public JComboBox getCbCategory() {
		return cbCategory;
	}


	public void setCbCategory(JComboBox cbCategory) {
		this.cbCategory = cbCategory;
	}


	public JTextField getTfAmount() {
		return tfAmount;
	}


	public void setTfAmount(JTextField tfAmount) {
		this.tfAmount = tfAmount;
	}


	public JComboBox getComboBoxPaymentMethod() {
		return comboBoxPaymentMethod;
	}


	public void setComboBoxPaymentMethod(JComboBox comboBoxPaymentMethod) {
		this.comboBoxPaymentMethod = comboBoxPaymentMethod;
	}


	public JTextField getTfChequeNo() {
		return tfChequeNo;
	}


	public void setTfChequeNo(JTextField tfChequeNo) {
		this.tfChequeNo = tfChequeNo;
	}


	public JTextField getTfChequeDate() {
		return tfChequeDate;
	}


	public void setTfChequeDate(JTextField tfChequeDate) {
		this.tfChequeDate = tfChequeDate;
	}


	public JButton getBtnChequeDate() {
		return btnChequeDate;
	}


	public void setBtnChequeDate(JButton btnChequeDate) {
		this.btnChequeDate = btnChequeDate;
	}


	

	public JTextField getTfCreditCard() {
		return tfCreditCard;
	}


	public void setTfCreditCard(JTextField tfCreditCard) {
		this.tfCreditCard = tfCreditCard;
	}


	public JTextField getTfDate() {
		return tfDate;
	}


	public void setTfDate(JTextField tfDate) {
		this.tfDate = tfDate;
	}


	public JButton getBtnDate() {
		return btnDate;
	}


	public void setBtnDate(JButton btnDate) {
		this.btnDate = btnDate;
	}


	public JTextArea getTaDescription() {
		return taDescription;
	}


	public void setTaDescription(JTextArea taDescription) {
		this.taDescription = taDescription;
	}


	public JButton getBtnAdd() {
		return btnAdd;
	}


	public void setBtnAdd(JButton btnAdd) {
		this.btnAdd = btnAdd;
	}


	public JButton getBtnSave() {
		return btnSave;
	}


	public void setBtnSave(JButton btnSave) {
		this.btnSave = btnSave;
	}


	public JTable getTable() {
		return table;
	}


	public void setTable(JTable table) {
		this.table = table;
	}
	
	public JTextField getTfBranch() {
		return tfBranch;
	}
	public void setTfBranch(JTextField tfBranch) {
		this.tfBranch = tfBranch;
	}
	public JTextField getTfBank() {
		return tfBank;
	}
	public void setTfBank(JTextField tfBank) {
		this.tfBank = tfBank;
	}
	public JRadioButton getRdbtnExpense() {
		return rdbtnExpense;
	}
	public void setRdbtnExpense(JRadioButton rdbtnExpense) {
		this.rdbtnExpense = rdbtnExpense;
	}
	public JRadioButton getRdbtnIncome() {
		return rdbtnIncome;
	}
	public void setRdbtnIncome(JRadioButton rdbtnIncome) {
		this.rdbtnIncome = rdbtnIncome;
	}
	public JRadioButton getRdbtnPaySeller() {
		return rdbtnPaySeller;
	}
	public void setRdbtnPaySeller(JRadioButton rdbtnPaySeller) {
		this.rdbtnPaySeller = rdbtnPaySeller;
	}
	public JRadioButton getRdbtnAcceptPayment() {
		return rdbtnAcceptPayment;
	}
	public void setRdbtnAcceptPayment(JRadioButton rdbtnAcceptPayment) {
		this.rdbtnAcceptPayment = rdbtnAcceptPayment;
	}
	public ButtonGroup getButtonGroup() {
		return buttonGroup;
	}
	
	public JTextField getTfcustomerName() {
		return tfcustomerName;
	}
	public void setTfcustomerName(JTextField tfcustomerName) {
		this.tfcustomerName = tfcustomerName;
	}
	/*************************************************************************/
	public void addActionListenerOnButtons(ActionListener al)
	{
		btnAdd.addActionListener(al);
		btnChequeDate.addActionListener(al);
		btnDate.addActionListener(al);
		btnSave.addActionListener(al);
		rdbtnExpense.addActionListener(al);
		rdbtnIncome.addActionListener(al);
		rdbtnPaySeller.addActionListener(al);
		rdbtnAcceptPayment.addActionListener(al);
	}

	
	
}
